package com.zy.servlet.AjaxServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "Servlet", urlPatterns = "/getUser")
public class Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Servlet.doPost");
        String name = request.getParameter("name");
        System.out.println("name = " + name);
        String age = request.getParameter("age");
        System.out.println("age = " + age);
        System.out.println("Servlet.doGet");
        response.getWriter().write("success  from Servlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        System.out.println("name = " + name);
        String age = request.getParameter("age");
        System.out.println("age = " + age);
        System.out.println("Servlet.doGet");
        response.getWriter().write("{\"name\":\"su\",\"age\":18}");
    }
}
